<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Reader
 *
 * @author 梅小春 476984957@qq.com
 */
class Reader {

    public static function getBytes(&$f,$num){
        $bytes = [];
        for($i=0;$i<$num;$i++){
            $bytes[] = ord(fread($f, 1));
        }
        return $bytes;
    }
    public static function readLen(&$f,$num){
        return fread($f, $num);
    }
    
    public static function getTitle(&$f) {
        $bytes = self::readLen($f, 44);
        return $bytes;
    }
    
    public static function Integer(&$f){
        $bytes = self::readLen($f, 4);
        $res = unpack("i", $bytes);
        if($res){
            return current($res);
        }else{
            return null;
        }
    }
    
    public static function getShort(&$f){
        $bytes = self::readLen($f, 2);
        $res = unpack("s", $bytes);
        if($res){
            return current($res);
        }else{
            return null;
        }
    }

}
